﻿
'*******************************************************************
' Program: Data Center Visio Rack Tool
' Author: Albert E Edlund
' Date:
'
' Purpose:
'
'
'
'*******************************************************************


Imports Microsoft.Practices.EnterpriseLibrary.Common
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging


Imports System
Imports System.ComponentModel
Imports System.Collections.Generic

Imports System.Collections.ObjectModel


Imports System.Data
Imports System.Data.Common
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.IO
Imports System.Xml
Imports System.Collections
Imports System.Runtime.InteropServices



Imports DC_Rack.Support.clsVisioSupport
Imports DC_Rack.Objects.dc_Component
Imports Microsoft.Office.Interop.Visio
Imports DC_Rack.Objects.dc_Product
Imports DC_Rack.Objects.clsDC_RackData

'
'
'
Public Class clsProductData
    Inherits dc_Product

#Region " Properties and Declarations "

    Public m_db As Database
    Public m_ds As DataSet
    Public m_dt As DataTable

    Public m_dc As dc_Product
    Public m_oc As Collection(Of dc_Product)

    Private strUserId As String

    Private m_deleteCommand As DbCommand
    Private m_insertCommand As DbCommand
    Private m_updateCommand As DbCommand


    Private m_clsPortMasters As DC_Rack.Objects.clsPortMaster
    Private m_clsSlotMasters As DC_Rack.Objects.clsSlotMaster


    Private m_clsVisio As DC_Rack.Support.clsVisioSupport


    Public Const readAll As String = "selectTblProductData"

    ' who am I
    Private myEnum As DC_RackTables = DC_RackTables.tblProductData


    '
    ' collections that we use 
    '
    Private m_colMasterErrors As Collection
    Property _MasterErrors() As Collection
        Get
            If m_colMasterErrors Is Nothing Then
                m_colMasterErrors = New Collection
            End If
            _MasterErrors = m_colMasterErrors
        End Get
        Set(ByVal value As Collection)
            m_colMasterErrors = value
        End Set
    End Property

    Private m_intProductCount As Integer
    Property _ProductCount() As Integer
        Get
            _ProductCount = m_intProductCount
        End Get
        Set(ByVal value As Integer)
            m_intProductCount = value
        End Set
    End Property

    Private m_colStencils As Collection
    Property _colStencils() As Collection
        Get
            If m_colStencils Is Nothing Then
                Return New Collection
            End If
            Return Me.m_colStencils
        End Get
        Set(ByVal value As Collection)
            Me.m_colStencils = value
        End Set
    End Property

    Private m_colMasters As Collection
    Property _colMasters() As Collection
        Get
            If m_colMasters Is Nothing Then
                Return New Collection
            End If
            Return Me.m_colMasters
        End Get
        Set(ByVal value As Collection)
            Me.m_colMasters = value
        End Set
    End Property

    Private m_colPortMasters As Collection(Of dc_PortBase)
    Property _colPortMaster() As Collection(Of dc_PortBase)
        Get
            If m_colPortMasters Is Nothing Then
                m_colPortMasters = New Collection(Of dc_PortBase)
            End If
            Return Me.m_colPortMasters
        End Get
        Set(ByVal value As Collection(Of dc_PortBase))
            If m_colPortMasters Is Nothing Then
                m_colPortMasters = New Collection(Of dc_PortBase)
            End If
            Me.m_colPortMasters = value
        End Set
    End Property

    Private m_colSlotMasters As Collection(Of dc_SlotBase)
    Property _colSlotMaster() As Collection(Of dc_SlotBase)
        Get
            If m_colSlotMasters Is Nothing Then
                m_colSlotMasters = New Collection(Of dc_SlotBase)
            End If
            Return Me.m_colSlotMasters
        End Get
        Set(ByVal value As Collection(Of dc_SlotBase))
            If m_colSlotMasters Is Nothing Then
                m_colSlotMasters = New Collection(Of dc_SlotBase)
            End If
            m_colSlotMasters = value
        End Set
    End Property

    Property pDataTable() As DataTable
        Get
            If m_dt Is Nothing Then
                m_dt = New DataTable
            End If
            pDataTable = m_dt
        End Get
        Set(ByVal value As DataTable)
            m_dt = value
        End Set
    End Property

    Property _DataSet() As DataSet
        Get
            If m_ds Is Nothing Then
                m_ds = New DataSet
                m_ds.SchemaSerializationMode = SchemaSerializationMode.IncludeSchema
            End If
            Return Me.m_ds
        End Get
        Set(ByVal value As DataSet)
            m_ds = value
        End Set
    End Property


    '********* visio snippet vb.net visXXXX ******************
    Private _drawingApplication As Microsoft.Office.Interop.Visio.Application
    Public Property drawingApplication() As Microsoft.Office.Interop.Visio.Application
        Get
            Return Me._drawingApplication
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.Application)
            If (value Is Nothing) Then
                Throw New System.ArgumentNullException("ApplicationValueIsNull", _
                    "drawingApplication is Null.")
            End If
            Me._drawingApplication = value
        End Set
    End Property


    '********* visio snippet vb.net visXXXX ******************
    Private _drawingDocument As Microsoft.Office.Interop.Visio.Document
    Public Property drawingDocument() As Microsoft.Office.Interop.Visio.Document
        Get
            Return Me._drawingDocument
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.Document)
            If (value Is Nothing) Then
                Throw New System.ArgumentNullException("DocumentValueIsNull", _
                    "drawingDocument is Null.")
            End If
            Me._drawingDocument = value
        End Set
    End Property


    '********* visio snippet vb.net visXXXX ******************
    Private _drawingWindow As Microsoft.Office.Interop.Visio.Window
    Public Property drawingWindow() As Microsoft.Office.Interop.Visio.Window
        Get
            Return Me._drawingWindow
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.Window)
            If (value Is Nothing) Then
                Throw New System.ArgumentNullException("WindowValueIsNull", _
                    "drawingWindow is Null.")
            End If
            Me._drawingWindow = value
        End Set
    End Property




    Private m_StencilPath As String
    Property _StencilPath() As String
        Get
            Return Me.m_StencilPath
        End Get
        Set(ByVal value As String)
            Me.m_StencilPath = value
        End Set
    End Property

    Private m_visshape As Microsoft.Office.Interop.Visio.Shape
    Property _VisShape() As Microsoft.Office.Interop.Visio.Shape
        Get
            Return Me.m_visshape
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.Shape)
            Me.m_visshape = value
        End Set
    End Property

    '
    ' for validation pass in a form
    ' 
    Private m_parentform As Object 'frmProductVal
    Property _ParentForm() As Object
        Get
            Return Me.m_parentform
        End Get
        Set(ByVal value As Object)
            Me.m_parentform = value
        End Set
    End Property



#End Region

#Region " Move/Transform Data "


    '
    ' create columns
    '
    Public Sub CreateTableColumns(ByRef tempTable As DataTable)

        Dim newDC As dc_Product = New dc_Product(strUserId)

        Try

            Dim colProdKey As New System.Data.DataColumn
            colProdKey.ColumnName = "prodKey"
            colProdKey.DataType = GetType(Integer)
            colProdKey.DefaultValue = newDC.prodKey
            tempTable.Columns.Add(colProdKey)

            Dim colProdVendor As New System.Data.DataColumn
            colProdVendor.ColumnName = "prodVendor"
            colProdVendor.DataType = GetType(String)
            colProdVendor.DefaultValue = newDC.prodVendor
            tempTable.Columns.Add(colProdVendor)

            Dim colProdProduct As New System.Data.DataColumn
            colProdProduct.ColumnName = "prodProduct"
            colProdProduct.DataType = GetType(String)
            colProdProduct.DefaultValue = newDC.prodProduct
            tempTable.Columns.Add(colProdProduct)

            Dim colProdModel As New System.Data.DataColumn
            colProdModel.ColumnName = "prodModel"
            colProdModel.DataType = GetType(String)
            colProdModel.DefaultValue = newDC.prodModel
            tempTable.Columns.Add(colProdModel)

            Dim colProdPartNr As New System.Data.DataColumn
            colProdPartNr.ColumnName = "prodPartNr"
            colProdPartNr.DataType = GetType(String)
            colProdPartNr.DefaultValue = newDC.prodPartNr
            tempTable.Columns.Add(colProdPartNr)

            Dim colProdSlots As New System.Data.DataColumn
            colProdSlots.ColumnName = "prodSlots"
            colProdSlots.DataType = GetType(Integer)
            colProdSlots.DefaultValue = newDC.prodSlots
            tempTable.Columns.Add(colProdSlots)

            Dim colprodMasterTop As New System.Data.DataColumn
            colprodMasterTop.ColumnName = "prodMasterTop"
            colprodMasterTop.DataType = GetType(String)
            colprodMasterTop.DefaultValue = newDC.prodMasterTop
            tempTable.Columns.Add(colprodMasterTop)

            Dim colProdMasterRear As New System.Data.DataColumn
            colProdMasterRear.ColumnName = "prodMasterRear"
            colProdMasterRear.DataType = GetType(String)
            colProdMasterRear.DefaultValue = newDC.prodMasterRear
            tempTable.Columns.Add(colProdMasterRear)

            Dim colProdMasterFront As New System.Data.DataColumn
            colProdMasterFront.ColumnName = "prodMasterFront"
            colProdMasterFront.DataType = GetType(String)
            colProdMasterFront.DefaultValue = newDC.prodMasterFront
            tempTable.Columns.Add(colProdMasterFront)

            Dim colProdMasterLogical As New System.Data.DataColumn
            colProdMasterLogical.ColumnName = "prodMasterLogical"
            colProdMasterLogical.DataType = GetType(String)
            colProdMasterLogical.DefaultValue = newDC.prodMasterLogical
            tempTable.Columns.Add(colProdMasterLogical)

            Dim colProdStencil As New System.Data.DataColumn
            colProdStencil.ColumnName = "prodStencil"
            colProdStencil.DataType = GetType(String)
            colProdStencil.DefaultValue = newDC.prodStencil
            tempTable.Columns.Add(colProdStencil)

            Dim colprodType As New System.Data.DataColumn
            colprodType.ColumnName = "prodType"
            colprodType.DataType = GetType(Integer)
            colprodType.DefaultValue = newDC.prodType
            tempTable.Columns.Add(colprodType)

            Dim colprodSubtype As New System.Data.DataColumn
            colprodSubtype.ColumnName = "prodSubtype"
            colprodSubtype.DataType = GetType(Integer)
            colprodSubtype.DefaultValue = newDC.prodSubtype
            tempTable.Columns.Add(colprodSubtype)

            Dim colProdErrorSlot As New System.Data.DataColumn
            colProdErrorSlot.ColumnName = "prodErrorSlot"
            colProdErrorSlot.DataType = GetType(Boolean)
            colProdErrorSlot.DefaultValue = newDC.prodErrorSlot
            tempTable.Columns.Add(colProdErrorSlot)

            Dim colProdErrorPort As New System.Data.DataColumn
            colProdErrorPort.ColumnName = "prodErrorPort"
            colProdErrorPort.DataType = GetType(Boolean)
            colProdErrorPort.DefaultValue = newDC.prodErrorPort
            tempTable.Columns.Add(colProdErrorPort)

            Dim colProdErrorGeneral As New System.Data.DataColumn
            colProdErrorGeneral.ColumnName = "prodErrorGeneral"
            colProdErrorGeneral.DataType = GetType(Boolean)
            colProdErrorGeneral.DefaultValue = newDC.prodErrorGeneral
            tempTable.Columns.Add(colProdErrorGeneral)

            Dim colProdBTU As New System.Data.DataColumn
            colProdBTU.ColumnName = "prodBTU"
            colProdBTU.DataType = GetType(Double)
            colProdBTU.DefaultValue = newDC.prodBTU
            tempTable.Columns.Add(colProdBTU)

            Dim colProdWeight As New System.Data.DataColumn
            colProdWeight.ColumnName = "prodWeight"
            colProdWeight.DataType = GetType(Double)
            colProdWeight.DefaultValue = newDC.prodWeight
            tempTable.Columns.Add(colProdWeight)

            Dim colProdPower As New System.Data.DataColumn
            colProdPower.ColumnName = "prodPower"
            colProdPower.DataType = GetType(Double)
            colProdPower.DefaultValue = newDC.prodPower
            tempTable.Columns.Add(colProdPower)

            Dim colProdVoltage As New System.Data.DataColumn
            colProdVoltage.ColumnName = "prodVoltage"
            colProdVoltage.DataType = GetType(Integer)
            colProdVoltage.DefaultValue = newDC.prodVoltage
            tempTable.Columns.Add(colProdVoltage)

            Dim colProdLastUpdate As New System.Data.DataColumn
            colProdLastUpdate.ColumnName = "prodLastUpdate"
            colProdLastUpdate.DataType = GetType(Date)
            colProdLastUpdate.DefaultValue = newDC.prodLastUpdate
            tempTable.Columns.Add(colProdLastUpdate)

            Dim colProdLastEdit As New System.Data.DataColumn
            colProdLastEdit.ColumnName = "prodLastEdit"
            colProdLastEdit.DataType = GetType(String)
            colProdLastEdit.DefaultValue = newDC.prodLastEdit
            tempTable.Columns.Add(colProdLastEdit)

            Dim colProdComments As New System.Data.DataColumn
            colProdComments.ColumnName = "prodComments"
            colProdComments.DataType = GetType(String)
            colProdComments.DefaultValue = newDC.prodComments
            tempTable.Columns.Add(colProdComments)
            newDC = Nothing


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

        If newDC IsNot Nothing Then
            newDC = Nothing
        End If


    End Sub

    '
    ' use this initially for adding rows
    '
    Public Sub movePropertiesToDataRow _
                (ByRef tempRow As DataRow, _
                 ByVal tempDC As dc_Product)

        Try

            With tempDC
                tempRow.SetField("prodKey", .prodKey)
                tempRow.SetField("prodVendor", .prodVendor)
                tempRow.SetField("prodProduct", .prodProduct)
                tempRow.SetField("prodModel", .prodModel)
                tempRow.SetField("prodPartNr", .prodPartNr)
                tempRow.SetField("prodSlots", .prodSlots)
                tempRow.SetField("prodMasterTop", .prodMasterTop)
                tempRow.SetField("prodMasterRear", .prodMasterRear)
                tempRow.SetField("prodMasterFront", .prodMasterFront)
                tempRow.SetField("prodMasterLogical", .prodMasterLogical)
                tempRow.SetField("prodStencil", .prodStencil)
                tempRow.SetField("prodType", .prodType)
                tempRow.SetField("prodSubtype", .prodSubtype)
                tempRow.SetField("prodErrorSlot", .prodErrorSlot)
                tempRow.SetField("prodErrorPort", .prodErrorPort)
                tempRow.SetField("prodErrorGeneral", .prodErrorGeneral)

                tempRow.SetField("prodBTU", .prodBTU)
                tempRow.SetField("prodWeight", .prodWeight)
                tempRow.SetField("prodPower", .prodPower)
                tempRow.SetField("prodVoltage", .prodVoltage)

                tempRow.SetField("prodComments", .prodComments)
                tempRow.SetField("prodLastUpdate", .prodLastUpdate)
                tempRow.SetField("prodLastEdit", strUserId)
            End With

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub


    '
    ' for reading records
    '
    Public Sub moveDataRowToProperties _
            (ByVal tempRow As DataRow)

        Try

            With m_dc
                .initProperties()
                .prodKey = tempRow.Item("prodKey")
                .prodVendor = tempRow.Item("prodVendor")
                .prodProduct = tempRow.Item("prodProduct")
                .prodModel = tempRow.Item("prodModel")
                .prodPartNr = tempRow.Item("prodPartNr")
                .prodSlots = tempRow.Item("prodSlots")

                .prodStencil = tempRow.Item("prodStencil")
                .prodMasterFront = tempRow.Item("prodMasterFront")
                .prodMasterRear = tempRow.Item("prodMasterRear")
                .prodMasterTop = tempRow.Item("prodMasterTop")
                .prodMasterLogical = tempRow.Item("prodMasterLogical")

                .prodType = tempRow.Item("prodType")
                .prodSubtype = tempRow.Item("prodSubtype")

                .prodErrorGeneral = tempRow.Item("prodErrorGeneral")
                .prodErrorPort = tempRow.Item("prodErrorPort")
                .prodErrorSlot = tempRow.Item("prodErrorSlot")

                .prodBTU = tempRow.Item("prodBTU")
                .prodWeight = tempRow.Item("prodWeight")
                .prodPower = tempRow.Item("prodPower")
                .prodVoltage = tempRow.Item("prodVoltage")

                .prodComments = tempRow.Item("prodComments")
                .prodLastEdit = tempRow.Item("prodLastEdit")
                .prodLastUpdate = tempRow.Item("prodLastUpdate")

            End With


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    ' for reading records
    '
    Public Sub moveDataRowToProperties _
            (ByVal tempRow As DataRow, _
             ByRef tempDC As dc_Product)

        Try

            With tempDC
                .initProperties()
                .prodKey = tempRow.Item("prodKey")
                .prodVendor = tempRow.Item("prodVendor")
                .prodProduct = tempRow.Item("prodProduct")
                .prodModel = tempRow.Item("prodModel")
                .prodPartNr = tempRow.Item("prodPartNr")
                .prodSlots = tempRow.Item("prodSlots")

                .prodStencil = tempRow.Item("prodStencil")
                .prodMasterFront = tempRow.Item("prodMasterFront")
                .prodMasterRear = tempRow.Item("prodMasterRear")
                .prodMasterTop = tempRow.Item("prodMasterTop")
                .prodMasterLogical = tempRow.Item("prodMasterLogical")

                .prodType = tempRow.Item("prodType")
                .prodSubtype = tempRow.Item("prodSubtype")

                .prodErrorGeneral = tempRow.Item("prodErrorGeneral")
                .prodErrorPort = tempRow.Item("prodErrorPort")
                .prodErrorSlot = tempRow.Item("prodErrorSlot")

                .prodBTU = tempRow.Item("prodBTU")
                .prodWeight = tempRow.Item("prodWeight")
                .prodPower = tempRow.Item("prodPower")
                .prodVoltage = tempRow.Item("prodVoltage")

                .prodComments = tempRow.Item("prodComments")
                .prodLastEdit = tempRow.Item("prodLastEdit")
                .prodLastUpdate = tempRow.Item("prodLastUpdate")

            End With


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    ' for moving datatable to collection for wpf
    '
    Public Sub moveDataTableToObservableCollection _
            (ByVal dtTemp As DataTable)

        Try

            If 0 < dtTemp.Rows.Count Then

                If m_oc IsNot Nothing Then
                    m_oc = Nothing
                    m_oc = New Collection(Of dc_Product)
                Else
                    m_oc = New Collection(Of dc_Product)
                End If

                Dim drTemp As DataRow
                Dim dcTemp As dc_Product
                For Each drTemp In dtTemp.Rows
                    dcTemp = New dc_Product
                    moveDataRowToProperties(drTemp, dcTemp)
                    m_oc.Add(dcTemp)
                Next

            End If

        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Public Function moveDataTableToXML() As XmlDocument

        Dim writer = New System.IO.StringWriter
        Dim m_dt_xml As Xml.XmlDocument = Nothing

        Try

            m_dt.WriteXml(writer, XmlWriteMode.WriteSchema, True)
            m_dt_xml = Nothing
            m_dt_xml = New Xml.XmlDocument
            m_dt_xml.LoadXml(writer.ToString)

        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        Finally

            writer = Nothing

        End Try

        Return m_dt_xml


    End Function

#End Region

#Region " Data Validation "

    ' step through the product table and gather data based upon the view
    ' requested. Optionally we can clear existing information.
    ' When verifying/gleaning this is intended to be called twice so that
    ' both views can be captured.
    '

    Public Sub initProductVerify()

        Try
            '
            ' setup the master ports class
            '
            If m_clsPortMasters Is Nothing Then
                m_clsPortMasters = New DC_Rack.Objects.clsPortMaster
            End If
            ' setup the local stuff
            If _colPortMaster Is Nothing Then
                _colPortMaster = New Collection(Of dc_PortBase)
            End If

            '
            ' setup the master slots class
            '
            If m_clsSlotMasters Is Nothing Then
                m_clsSlotMasters = New DC_Rack.Objects.clsSlotMaster
            End If
            ' setup the local copy
            If _colSlotMaster Is Nothing Then
                _colSlotMaster = New Collection(Of dc_SlotBase)
            End If

            If m_colMasterErrors Is Nothing Then
                m_colMasterErrors = New Collection
            End If



        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub


    '
    '
    '
    Public Sub stepProductDataRS _
            (Optional ByVal strView As String = "rear", _
            Optional ByVal blnClear As Boolean = True)


        Dim strCurrStep As String
        strCurrStep = "start"
        Dim vsoDocStencil As Microsoft.Office.Interop.Visio.Document
        Dim visDocuments As Microsoft.Office.Interop.Visio.Documents

        Dim intX As Integer = 0
        Dim intY As Integer = 0
        ' how many records
        Dim intRecords As Integer = 0
        Dim strMaster As String = ""
        Dim vsoMaster As Microsoft.Office.Interop.Visio.Master
        Dim lngProdKey As Int32
        Dim lclMaster As Microsoft.Office.Interop.Visio.Master
        Dim blnLoaded As Boolean = False
        Dim blnFound As Boolean
        blnFound = False
        Dim intprodSubtype As Integer

        Dim strStencil As String = ""
        Dim strMasterSelect As String = ""

        Dim drRow As DataRow


        Try

            Dim intErrCt As Integer = 0

            strCurrStep = "clear collections"
            If blnClear = True Then
                If 0 < m_colMasterErrors.Count Then
                    For intX = m_colMasterErrors.Count To 1 Step -1
                        m_colMasterErrors.Remove(intX)
                    Next intX
                End If
                ' clear the collections 
                _colPortMaster = Nothing
                _colPortMaster = New Collection(Of dc_PortBase)
                _colSlotMaster = Nothing
                _colSlotMaster = New Collection(Of dc_SlotBase)
                m_dt = Nothing
                m_dt = New DataTable

                ' since we update the records as we find them with the current data
                ' clear the records at the beginning
                dbClearErrorFlags()
            End If

            ' go get the records
            strCurrStep = "read product recordset"
            ' load the product table into the dataset 
            If m_dt.Rows.Count < 1 Then
                dbSelectAllProducts()
                _ParentForm.lblProductCount.Text = m_dt.Rows.Count
            End If

            _ProductCount = m_dt.Rows.Count

            If _ProductCount < 1 Then
                Exit Sub
            End If


            For Each drRow In m_dt.Rows

                vsoMaster = Nothing
                lclMaster = Nothing
                blnFound = False
                lngProdKey = -1

                ' get the product data row
                strCurrStep = "get prodkey"
                lngProdKey = drRow("prodKey")
                '
                ' get stencil name to save with master port data
                '
                strCurrStep = "get stencil"
                If IsDBNull(drRow("prodStencil")) Then
                    logProductError(lngProdKey, "general", "has no product stencil")
                    GoTo FindNext
                Else
                    strStencil = drRow("prodStencil")
                End If

                strCurrStep = "create master select"
                If strView = "rear" Or strView = "front" Then strMasterSelect = strView
                If strView = "cable" Then
                    If IsDBNull(drRow("prodCableView")) Then
                        logProductError(lngProdKey, "general", "CableView is Null")
                        GoTo FindNext
                    End If
                    strMasterSelect = drRow("prodCableView")
                End If
                If strView = "status" Then
                    If IsDBNull(drRow("prodStatusView")) Then
                        logProductError(lngProdKey, "general", "StatusView is Null")
                        GoTo FindNext
                    End If
                    strMasterSelect = drRow("prodStatusView")
                End If

                Select Case strMasterSelect
                    Case "rear"
                        If IsDBNull(drRow("prodMasterRear")) Then
                            logProductError(lngProdKey, "general", "MasterRear is Null")
                            GoTo FindNext
                        End If
                        strMaster = drRow("prodMasterRear")
                    Case "front"
                        If IsDBNull(drRow("prodMasterFront")) Then
                            logProductError(lngProdKey, "general", "MasterFront is Null")
                            GoTo FindNext
                        End If
                        strMaster = drRow("prodMasterFront")
                End Select

                Select Case strMaster
                    Case "na"
                        GoTo FindNext
                    Case ""
                        GoTo FindNext
                End Select

                '
                ' first check to see if the shape is in the document stencil
                '
                Try
                    strCurrStep = "find master"
                    lclMaster = Me.drawingDocument.Masters(strMaster)
                    If Not (lclMaster Is Nothing) Then
                        vsoMaster = lclMaster
                        _colStencils.Add("document")
                        _colMasters.Add(vsoMaster.Name)
                        blnFound = True

                    End If
                Catch
                    ' got try the next one
                End Try

                '
                ' if not in document then go read the external stencil
                '
                Try
                    If blnFound = False Then
                        LoadStencil(strStencil)

                        visDocuments = Me.drawingDocument.Application.Documents
                        vsoDocStencil = visDocuments.Item(strStencil)
                        lclMaster = vsoDocStencil.Masters(strMaster)
                        If Not (lclMaster Is Nothing) Then
                            vsoMaster = lclMaster
                            ' save the stencil name
                            _colStencils.Add(strStencil)
                            ' save the master name
                            _colMasters.Add(vsoMaster.Name)
                            blnFound = True
                        End If
                    End If
                Catch
                    GoTo FindNext
                End Try

                ' get the product index
                strCurrStep = "get prodSubtype"
                If IsDBNull(drRow("prodSubtype")) Then
                    logProductError(lngProdKey, "general", "prodSubtype is Null")
                    GoTo FindNext
                Else
                    intprodSubtype = drRow("prodSubtype")
                End If

                If blnFound = False Then
                    strCurrStep = "log not found"
                    Dim strError As String
                    strError = ""
                    strError = "notfound," & strStencil & "," & strMaster & "," & strView & "," & strMasterSelect
                    logProductError(lngProdKey, "general", strError)
                    GoTo FindNext
                Else
                    ' compute a rack units
                    strCurrStep = "get rackunits"
                    Dim dblUHeight As Double
                    dblUHeight = 1.75
                    Dim intUnits As Integer
                    intUnits = getRackUnits(vsoMaster, dblUHeight)

                    ' cycle through the connection points
                    strCurrStep = "handle connection points"

                    HandleConnectionPoints(vsoMaster, strMasterSelect, lngProdKey, intprodSubtype)

                End If

FindNext:
                strCurrStep = "move next"
            Next drRow

            ' this happens here because we do not want to search the error list
            ' at every connection point when doing the slots
            '

            Dim intCount
            intCount = Me._colPortMaster.Count
            intCount = m_colMasterErrors.Count

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try


    End Sub

    '
    ' pass in a product record key, scan routine, and error string and save it to the 
    ' error collection
    '
    Private Sub logProductError(ByVal lngRecord As Int32, _
                ByVal strSource As String, _
                ByVal strError As String)

        Try
            If m_colMasterErrors Is Nothing Then
                m_colMasterErrors = New Collection
            End If

            strError = CStr(lngRecord) & "," & strSource & "," & strError
            m_colMasterErrors.Add(strError)

        Catch ex As Exception

        End Try


    End Sub

    '
    ' test to see if stencil is already loaded
    '
    Private Function TestStencilLoaded _
        (ByVal strStencil As String) _
        As Boolean


        Dim vsoDocs As Microsoft.Office.Interop.Visio.Documents
        Dim intDoc As Integer
        Dim blnReturn As Boolean = False
        Dim strDocName As String


        Try

            ' Find the stencil in the Document collection by name.
            vsoDocs = Me.drawingDocument.Application.Documents

            For intDoc = 1 To vsoDocs.Count
                strDocName = vsoDocs.Item(intDoc).Name
                If LCase(strDocName) = LCase(strStencil) Then
                    blnReturn = True
                    Exit For
                End If
            Next intDoc

            TestStencilLoaded = blnReturn

        Catch com As COMException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Log Only Policy")
            TestStencilLoaded = blnReturn
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            TestStencilLoaded = blnReturn
        End Try

    End Function

    '
    ' load a stencil
    '
    Private Function LoadStencil _
            (ByVal strStencil As String) _
            As Boolean

        Dim blnReturn As Boolean = False
        Dim strTarget = _StencilPath & strStencil

        Try
            If TestStencilLoaded(strStencil) = True Then
                blnReturn = True
            Else
                If (System.IO.File.Exists(strTarget)) = True Then
                    Me.drawingDocument.Application.Documents.OpenEx(strTarget, _
                        (CShort(Microsoft.Office.Interop.Visio. _
                            VisOpenSaveArgs.visOpenDocked) + _
                        CShort(Microsoft.Office.Interop.Visio. _
                            VisOpenSaveArgs.visOpenRO)))
                    blnReturn = True
                End If
            End If
            LoadStencil = blnReturn


        Catch com As COMException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Log Only Policy")
            LoadStencil = blnReturn
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            LoadStencil = blnReturn
        End Try

    End Function

    '
    ' given a master, attempt to figure out how many rack units it will
    ' take up
    '
    Private Function getRackUnits _
            (ByRef vsoMaster As Microsoft.Office.Interop.Visio.Master, _
            ByVal dblUHeight As Double) _
            As Integer

        Dim intReturn As Integer = -1

        Try

            If vsoMaster Is Nothing Then
                Debug.Print("transferred nothing")
                GoTo ExitHandler
            End If

            Dim visShape As Microsoft.Office.Interop.Visio.Shape
            Dim visCell As Microsoft.Office.Interop.Visio.Cell
            Dim dblHeight As Double

            Dim visShapes As Microsoft.Office.Interop.Visio.Shapes
            visShapes = vsoMaster.Shapes
            visShape = visShapes(1)

            If visShape.CellExists("height", False) = True Then
                visCell = visShape.Cells("height")
                dblHeight = visCell.Result("in")
                intReturn = CInt(dblHeight / dblUHeight) + Rnd(dblHeight / dblUHeight)
                ' Debug.Print vsoMaster.Name & " " & intReturn
            End If

ExitHandler:
            getRackUnits = intReturn

        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            getRackUnits = intReturn
        End Try

    End Function

#End Region

#Region " Slots and Ports "

    '
    ' read a master object and get a list of port and slot names
    '
    Private Sub HandleConnectionPoints _
            (ByRef visMaster As Microsoft.Office.Interop.Visio.Master, _
            ByVal intView As dc_Product.View, _
            ByVal lngProdKey As Int32, _
            ByVal intprodSubtype As Integer)

        Try
            If visMaster Is Nothing Then
                Debug.Print("transferred nothing")
                Exit Sub
            End If

            Dim visShape As Microsoft.Office.Interop.Visio.Shape
            Dim visRow As Microsoft.Office.Interop.Visio.Row
            Dim intX As Integer
            intX = 0
            Dim intY As Integer
            Dim clsPortItem As dc_PortBase
            Dim clsSlotItem As dc_SlotBase
            Dim blnTestName As Boolean
            Dim strErrorMsg As String
            Dim colTemp As Collection
            Dim colEnds As Collection(Of dc_SlotBase.EndPoints)

   
            Dim returnValue As String()

            visShape = visMaster.Shapes(1)
            If visShape.SectionExists(VisSectionIndices.visSectionConnectionPts, False) = True Then
                intX = visShape.Section(VisSectionIndices.visSectionConnectionPts).Count
                If 0 < intX Then
                    For intY = 0 To intX - 1
                        strErrorMsg = ""
                        visRow = visShape.Section(VisSectionIndices.visSectionConnectionPts).Row(intY)
                        ' simple test to get started, name testing done in item class
                        If LCase(Left(visRow.Name, 4)) = "port" Then
                            clsPortItem = New dc_PortBase
                            With clsPortItem
                                .portName = visRow.Name
                                .portProductKey = lngProdKey
                                .portProductView = intView
                                blnTestName = m_dc.isWellFormedName(visRow.Name)
                                If blnTestName = True Then
                                    .portWellFormedName = True
                                Else
                                    strErrorMsg = "Malformed Name," & visRow.Name
                                    logProductError(lngProdKey, "port", strErrorMsg)
                                End If

                                'If Me._colPortMaster.ExistsPortMaster(clsPortItem) = False Then
                                'Me._colPortMaster.Add(clsPortItem)
                                'Else
                                ' clear it
                                clsPortItem = Nothing
                                'End If
                            End With
                        End If ' test for port eyecatcher


                        If LCase(Left(visRow.Name, 4)) = "slot" Then
                            clsSlotItem = New dc_SlotBase
                            With clsSlotItem
                                ' slotid get's modified because it is only the first two fields
                                Dim intCount As Integer = 0
                                colTemp = Nothing
                                colTemp = New Collection
                                colEnds = Nothing
                                colEnds = New Collection(Of dc_SlotBase.EndPoints)

                                returnValue = visRow.Name.Split({"_"c}, _
                                        3, StringSplitOptions.None)

                                .slotId = returnValue(0) & "_" & returnValue(1)
                                .slotProductKey = lngProdKey
                                .slotProductView = intView


                                'blnTestName = m_clsStrings.isWellFormedName(visRow.Name)
                                'If blnTestName = True Then
                                '    .pSlotWellFormedName = True
                                'Else
                                '    strErrorMsg = "Malformed Name," & visRow.Name
                                '    logProductError(lngProdKey, "slot", strErrorMsg)
                                'End If

                                colEnds.Add(CInt(colTemp.Item(3)))
                                ._colEndPoints = colEnds

                                'If Me._colSlotMaster.ExistsSlotMaster(clsSlotItem) = False Then
                                'Me._colSlotMaster.Add(clsSlotItem)
                                'Else
                                'handleIdentifiedSlot(clsSlotItem)
                                'End If

                            End With
                        End If ' end test for slot item

                    Next intY ' get the next connection point
                End If ' test the connection point count for gt zero
            End If

        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try


    End Sub

    '
    ' we have found this slot in the list already
    ' with a rack we may see a given slot four times (front/back, both sides)
    '
    Private Sub handleIdentifiedSlot _
            (ByVal clsSlotItem As dc_SlotBase)

        Try

            'Dim colTempIn As Collection
            'colTempIn = New Collection

            'Dim colTempOut As Collection
            'colTempOut = New Collection

            ''
            '' create a temp slot item
            ''
            'Dim clsSlotTemp As dc_SlotBase = New dc_SlotBase


            '' find out where the slot is in the array
            'Dim intPointer As Integer
            'intPointer = _colSlotMaster.IndexOfSlotMaster(clsSlotItem)

            '' get the already existing item
            'clsSlotTemp = _colSlotMaster.GetItem(intPointer)
            '' get the list of endpoints from the existing item
            'colTempOut = clsSlotTemp.pSlotEndPoints
            '' get the list that was passed in to the routine
            'colTempIn = clsSlotItem.pSlotEndPoints
            '' since only one endpoint should have been passed in move it to
            '' the out collection. Special handling for racks so we don't add
            '' an endpoint more than once.
            'If clsSlotItem.m_slotproductkey = 1 Then
            '    Debug.Print("a")
            'End If
            'If clsSlotItem.prodSubtype = 21 Then
            '    If m_clsStrings.memberOfCollection(colTempOut, CInt(colTempIn.Item(1)), "integer") = False Then
            '        colTempOut.Add(CInt(colTempIn.Item(1)))
            '    End If
            'Else
            '    colTempOut.Add(CInt(colTempIn.Item(1)))
            '    If colTempOut.Count = 2 Then
            '        If ((m_clsStrings.memberOfCollection(colTempOut, 1, "integer") = True) _
            '            And (m_clsStrings.memberOfCollection(colTempOut, 2, "integer") = True)) Then
            '            clsSlotTemp.m_slotpairvalid = True
            '        End If
            '    End If
            'End If
            '' move the out collection to the temp item
            'clsSlotTemp.pSlotEndPoints = colTempOut

            '' replace the existing item with the temp
            'Dim blnResult As Boolean
            'blnResult = _colSlotMaster.Replace(intPointer, clsSlotTemp)

        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub


    '
    ' get the slot and port information from the product table
    ' and save them to the database
    '
    Public Sub saveConnectionInformation()

        Try

            Dim clsPorts As DC_Rack.Objects.clsPortMaster
            clsPorts = New DC_Rack.Objects.clsPortMaster
            ' so it can post back to calling form
            clsPorts._ParentForm = _ParentForm

            _ParentForm.lblStatus.Text = "Saving Port Masters"
            clsPorts.dbDeletePortMasters()

            ' move ours into there
            clsPorts.m_oc = _colPortMaster
            'clsPorts.buildPortMasterTable
            clsPorts.dbInsertPortMasterCollection()


            Dim clsSlots As DC_Rack.Objects.clsSlotMaster
            clsSlots = New DC_Rack.Objects.clsSlotMaster
            clsSlots._ParentForm = _ParentForm

            clsSlots.dbDeleteSlotMasters()

            ' move ours into there
            clsSlots.m_oc = _colSlotMaster
            _ParentForm.lblStatus.Text = "Saving Slot Masters"
            'clsSlots.buildSlotMasterTable
            clsSlots.dbInsertSlotMasterCollection()

        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub


    '
    ' go read the slot collection and if an error was detected save it to the
    ' errorlog collection
    '
    Public Sub scanSlotMasterItems()

        Try

            'Dim clsItem As dc_SlotBase
            'clsItem = New as dc_slotbase
            'Dim intX As Integer
            'Dim strEndPoints As String
            'Dim strErrorMsg As String
            'Dim intEndCount As Integer = 0

            '' this is a clsColTopology collection
            'For intX = 0 To Me._colSlotMaster.Count - 1
            '    strErrorMsg = ""
            '    clsItem = _colSlotMaster.Item(intX)
            '    With clsItem
            '        intEndCount = ._colEndPoints.Count
            '        Select Case intEndCount
            '            Case 2
            '                If (m_clsStrings.memberOfCollection(.m_endpoints, 1, "integer") = False) _
            '                    Or (m_clsStrings.memberOfCollection(.m_endpoints, 2, "integer") = False) Then
            '                    strEndPoints = m_clsStrings.BuildCsvString(.m_endpoints)
            '                    strErrorMsg = "InvalidPair" & "," & .m_slotid & "," & strEndPoints
            '                    logProductError(.m_slotproductkey, "slot", strErrorMsg)
            '                End If
            '            Case Else
            '                strEndPoints = m_clsStrings.BuildCsvString(.m_endpoints)
            '                strErrorMsg = "InvalidPair" & "," & .m_slotid & "," & strEndPoints
            '                logProductError(.m_slotproductkey, "slot", strErrorMsg)
            '        End Select
            '    End With
            'Next intX

        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try
    End Sub

    '
    '
    '
    Public Sub saveProductErrorFlags()

        Try

            Dim intX As Integer

            Dim lngKey As Int32
            Dim strKey As String
            Dim strRecord As String
            Dim strSource As String

  
            Dim returnValue As String()

            _ParentForm.lblStatus.Text = "Saving Error Flags"

            For intX = 1 To Me._MasterErrors.Count

                strRecord = _MasterErrors.Item(intX)

                returnValue = strRecord.Split({","c}, _
                    2, StringSplitOptions.None)

                strSource = returnValue(1)
                strKey = returnValue(0)
                lngKey = CLng(strKey)

                If lngKey < 1 Then GoTo NextRecord

                Select Case strSource
                    Case "port"
                        dbUpdatePortFlag(lngKey, True)
                    Case "slot"
                        dbUpdateSlotFlag(lngKey, True)
                    Case "general"
                        dbUpdateGeneralFlag(lngKey, True)
                End Select
NextRecord:
            Next intX

        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    Private Sub dbUpdatePortFlag(ByVal lngKey As Int32, ByVal blnFlag As Boolean)

        Dim strQuery As String = "UPDATE tblProductData " _
                      & "SET prodErrorPort = N'" & CStr(blnFlag) & "'" _
                      & " WHERE prodKey = " & lngKey


        Try

            Dim cmd As DbCommand = m_db.GetSqlStringCommand(strQuery)
            Dim affectedRows As Int16 = m_db.ExecuteNonQuery(cmd)

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    Private Sub dbUpdateSlotFlag(ByVal lngKey As Int32, ByVal blnFlag As Boolean)


        Dim strQuery As String = "UPDATE tblProductData " _
                        & "SET prodErrorSlot = N'" & CStr(blnFlag) & "'" _
                        & " WHERE prodKey = " & lngKey


        Try

            Dim cmd As DbCommand = m_db.GetSqlStringCommand(strQuery)
            Dim affectedRows As Int16 = m_db.ExecuteNonQuery(cmd)



        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    Private Sub dbUpdateGeneralFlag(ByVal lngKey As Int32, ByVal blnFlag As Boolean)

        Dim strQuery As String = "UPDATE tblProductData " _
                        & "SET prodErrorGeneral = N'" & CStr(blnFlag) & "'" _
                        & " WHERE prodKey = " & lngKey


        Try

            Dim cmd As DbCommand = m_db.GetSqlStringCommand(strQuery)
            Dim affectedRows As Int16 = m_db.ExecuteNonQuery(cmd)


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub


#End Region

#Region " Standard Calls "

    '
    '
    '
    Private Sub buildInsertProductDataCommand()


        Try
            m_insertCommand = m_db.GetStoredProcCommand("insertProductData")

            Dim cmdActive As DbCommand = m_insertCommand

            m_db.AddInParameter(cmdActive, "prodVendor", DbType.String, "prodVendor", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodProduct", DbType.String, "prodProduct", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodModel", DbType.String, "prodModel", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodSlots", DbType.Int16, "prodslots", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodMasterTop", DbType.String, "prodMasterTop", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodMasterRear", DbType.String, "prodMasterRear", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodMasterFront", DbType.String, "prodMasterFront", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodMasterLogical", DbType.String, "prodMasterLogical", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodStencil", DbType.String, "prodStencil", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodType", DbType.Int16, "prodType", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodSubtype", DbType.Int16, "prodSubtype", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodErrorSlot", DbType.Boolean, "prodErrorSlot", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodErrorPort", DbType.Boolean, "prodErrorPort", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodErrorGeneral", DbType.Boolean, "prodErrorGeneral", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodComments", DbType.String, "prodComments", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodPartNr", DbType.String, "prodPartNr", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodBTU", DbType.Double, "prodBTU", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodWeight", DbType.Double, "prodWeight", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodPower", DbType.Double, "prodPower", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodVoltage", DbType.Int16, "prodVoltage", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodLastUpdate", DbType.Date, "prodLastUpdate", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodLastEdit", DbType.String, "prodLastEdit", DataRowVersion.Current)



        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try


    End Sub

    '
    '
    '
    Private Sub buildDeleteProductDataCommand()



        Try
            m_deleteCommand = m_db.GetStoredProcCommand("deleteProductData")
            '	@ProdKey int,
            m_db.AddInParameter(m_deleteCommand, "prodKey", DbType.Int32, "prodKey", DataRowVersion.Current)

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If

        End Try

    End Sub


    '
    '
    '
    Private Sub buildUpdateProductDataCommand()


        Try

            m_updateCommand = m_db.GetStoredProcCommand("updateProductData")

            Dim cmdActive As DbCommand = m_updateCommand

            m_db.AddInParameter(cmdActive, "prodKey", DbType.Int32, "prodKey", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodVendor", DbType.String, "prodVendor", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodProduct", DbType.String, "prodProduct", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodModel", DbType.String, "prodModel", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodSlots", DbType.Int16, "prodslots", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodPartNr", DbType.String, "prodPartNr", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodMasterTop", DbType.String, "prodMasterTop", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodMasterRear", DbType.String, "prodMasterRear", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodMasterFront", DbType.String, "prodMasterFront", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodMasterLogical", DbType.String, "prodMasterLogical", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodStencil", DbType.String, "prodStencil", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodType", DbType.Int16, "prodType", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodSubtype", DbType.Int16, "prodSubtype", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodErrorSlot", DbType.Boolean, "prodErrorSlot", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodErrorPort", DbType.Boolean, "prodErrorPort", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodErrorGeneral", DbType.Boolean, "prodErrorGeneral", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodComments", DbType.String, "prodComments", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodBTU", DbType.Double, "prodBTU", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodWeight", DbType.Double, "prodWeight", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodPower", DbType.Double, "prodPower", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodVoltage", DbType.Int16, "prodVoltage", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodLastUpdate", DbType.Date, "prodLastUpdate", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "prodLastEdit", DbType.String, "prodLastEdit", DataRowVersion.Current)


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Public Function dbUpdateDataSet() As Int16

        Dim rowsAffected As Int16 = 0

        Try

            rowsAffected = m_db.UpdateDataSet(m_ds, DC_RackTables.tblProductData.ToString, _
                                        m_insertCommand, _
                                        m_updateCommand, _
                                        m_deleteCommand, _
                                        UpdateBehavior.Standard)
            'msgbox rowsAffected

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If

        End Try

        Return rowsAffected

    End Function

    '
    ' create a record based on property values move it to the generic datatable
    ' then copy the table to the database
    '
    Public Function addProductDataSourceRecord _
            (ByVal tempDC As dc_Product, _
             Optional ByVal blnSilent As Boolean = False) _
             As Integer

        Dim intRowsAffected As Integer = 0

        Try

            initDataSetAndTable()

            Dim m_dr As DataRow = m_ds.Tables(DC_RackTables.tblProductData.ToString).NewRow
            movePropertiesToDataRow(m_dr, tempDC)
            m_ds.Tables(DC_RackTables.tblProductData.ToString).Rows.Add(m_dr)
            intRowsAffected = dbUpdateDataSet()

            If blnSilent = False Then
                MsgBox("DataRowsUpated = " & intRowsAffected)
            End If

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

        Return intRowsAffected

    End Function

    '
    '
    '
    Public Sub initDataSetAndTable()

        Try

            ' make sure the root stuff is there
            If m_ds Is Nothing Then
                m_ds = New DataSet
            Else
                m_ds = Nothing
                m_ds = New DataSet
            End If
            m_ds.SchemaSerializationMode = SchemaSerializationMode.IncludeSchema

            If m_dt Is Nothing Then
                m_dt = New DataTable
            Else
                m_dt = Nothing
                m_dt = New DataTable
            End If

            If m_oc Is Nothing Then
                m_oc = New Collection(Of dc_Product)
            Else
                m_oc = Nothing
                m_oc = New Collection(Of dc_Product)
            End If

            If m_dc IsNot Nothing Then
                m_dc = Nothing
                m_dc = New dc_Product(strUserId)
            Else
                m_dc = New dc_Product(strUserId)
            End If

            CreateTableColumns(m_dt)
            m_dt.TableName = DC_RackTables.tblProductData.ToString

            m_ds.Tables.Add(m_dt)

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try



    End Sub




#End Region

#Region " database calls "

    '
    '
    '
    Private Sub dbClearErrorFlags()

        Dim dateNow As Date = Now()
        Dim strNow As String = CStr(Now)


        Try

            Dim cmd As DbCommand = m_db.GetStoredProcCommand("updateClearProductDataErrorFlags")
            m_db.AddInParameter(cmd, "@prodLastUpdate", DbType.Date, dateNow)
            m_db.ExecuteNonQuery(cmd)

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If

        End Try

    End Sub

    '
    '
    '
    Public Sub dbSelectAllProducts()

        Try



            initDataSetAndTable()

            ' Retrieve the initial data
            Dim cmd As DbCommand = m_db.GetStoredProcCommand(Objects.clsProductData.readAll)
            m_db.LoadDataSet(cmd, m_ds, DC_RackTables.tblProductData.ToString)

            m_dt = m_ds.Tables(DC_RackTables.tblProductData.ToString)


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    ' need to collect product data for components with active ports
    '
    Public Sub dbSelectProductDataForPortTable()

        Try


            If m_dc IsNot Nothing Then
                m_dc = Nothing
                m_dc = New dc_Product
            Else
                m_dc = New dc_Product
            End If

            initDataSetAndTable()

            ' Retrieve the initial data
            Dim cmd As DbCommand = m_db.GetStoredProcCommand("selectProductDataForPortTable")
            m_db.LoadDataSet(cmd, m_ds, DC_RackTables.tblProductData.ToString)

            m_dt = m_ds.Tables(DC_RackTables.tblProductData.ToString)


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub


    '
    ' need to collect product data for components
    '
    Public Sub dbSelectProductDataForComponentTable()

        Try


            If m_dc IsNot Nothing Then
                m_dc = Nothing
                m_dc = New dc_Product
            Else
                m_dc = New dc_Product
            End If

            initDataSetAndTable()

            ' Retrieve the initial data
            Dim cmd As DbCommand = m_db.GetStoredProcCommand("selectProductDataForComponentTable")
            m_db.LoadDataSet(cmd, m_ds, DC_RackTables.tblProductData.ToString)

            m_dt = m_ds.Tables(DC_RackTables.tblProductData.ToString)


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Public Sub dbSelectProductByKey(ByVal lngProdKey As Int32)

        Try

            initDataSetAndTable()

            ' Retrieve the initial data
            Dim cmd As DbCommand = m_db.GetStoredProcCommand("selectProductByKey")
            m_db.AddInParameter(cmd, "@prodKey", DbType.Int32, lngProdKey)
            m_db.LoadDataSet(cmd, m_ds, DC_RackTables.tblProductData.ToString)

            m_dt = m_ds.Tables(DC_RackTables.tblProductData.ToString)

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Public Sub dbSelectProductByCompKey(ByVal lngCompKey As Int32)

        Try

            initDataSetAndTable()

            ' Retrieve the initial data
            Dim cmd As DbCommand = m_db.GetStoredProcCommand("selectProductByCompKey")
            m_db.AddInParameter(cmd, "@compKey", DbType.Int32, lngCompKey)
            m_db.LoadDataSet(cmd, m_ds, DC_RackTables.tblProductData.ToString)

            m_dt = m_ds.Tables(DC_RackTables.tblProductData.ToString)

            If m_dt.Rows.Count = 1 Then
                moveDataRowToProperties(m_dt.Rows(0))
            End If


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub


#End Region

#Region " Visio Interaction "

    '
    '
    '
    Public Sub addTestProductDataProperties()

        With m_dc

            .prodKey = -1
            .prodVendor = "BigVendor"
            .prodProduct = "NewProduct"
            .prodModel = "NewestModel"
            .prodSlots = 1
            .prodWeight = 4.7
            .prodBTU = 19
            .prodPower = 125
            .prodVoltage = 120
            .prodPartNr = "test123"

        End With

    End Sub

    '
    '
    '
    Public Sub UpdateProductProperties _
            (ByRef visShape As Microsoft.Office.Interop.Visio.Shape, _
             ByVal drProduct As System.Data.DataRow)


        Try

            If Not (drProduct Is Nothing) Then

                With m_dc
                    .prodKey = drProduct.Field(Of Int32)("prodKey")
                    .prodVendor = drProduct.Field(Of String)("prodVendor")
                    .prodProduct = drProduct.Field(Of String)("prodProduct")
                    .prodModel = drProduct.Field(Of String)("prodModel")
                    .prodSlots = drProduct.Field(Of Integer)("prodSlots")
                    .prodWeight = drProduct.Field(Of Double)("prodWeight")
                    .prodBTU = drProduct.Field(Of Double)("prodBTU")
                    .prodPower = drProduct.Field(Of Double)("prodPower")
                    .prodVoltage = drProduct.Field(Of Int32)("prodVoltage")
                    .prodPartNr = drProduct.Field(Of String)("prodPartNr")
                End With

            Else
                addTestProductDataProperties()
            End If

            With m_dc
                m_clsVisio.ForceShapeData(visShape, "prodKey", .prodKey, "attrProductData")
                m_clsVisio.ForceShapeData(visShape, "prodVendor", .prodVendor, "attrProductData")
                m_clsVisio.ForceShapeData(visShape, "prodProduct", .prodProduct, "attrProductData")
                m_clsVisio.ForceShapeData(visShape, "prodModel", .prodModel, "attrProductData")
                m_clsVisio.ForceShapeData(visShape, "prodPartNr", .prodPartNr, "attrProductData")

                ' environmentals
                m_clsVisio.ForceShapeData(visShape, "prodBTU", .prodBTU, "attrProductData")
                m_clsVisio.ForceShapeData(visShape, "prodWeight", .prodWeight, "attrProductData")
                m_clsVisio.ForceShapeData(visShape, "prodPower", .prodPower, "attrProductData")
                m_clsVisio.ForceShapeData(visShape, "prodVoltage", .prodVoltage, "attrProductData")
            End With

        Catch com As COMException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
            MsgBox("Add Product Attributes " & ex.Message & " " & visShape.Name)
        End Try

    End Sub


    '
    ' using the current product data table find the stencils and masters and load them
    ' into the current document stencil
    '
    Public Sub preLoadDocumentStencil()


        If _colMasters Is Nothing Then
            _colMasters = New Collection
        Else
            _colMasters.Clear()
        End If

        If _colStencils Is Nothing Then
            _colStencils = New Collection
        Else
            _colStencils.Clear()
        End If


        Try


            Dim intVendorKey As Int32 = -1
            Dim strStencil As String = ""
            Dim strFront As String = ""
            Dim strRear As String = ""
            Dim strTop As String = ""

            Dim productQuery = From product In m_dt.AsEnumerable() _
                    Select product

            For Each p In productQuery
                intVendorKey = p.Field(Of Int32)("prodKey")
                strStencil = p.Field(Of String)("prodStencil")
                If _colStencils.Contains(strStencil) = False Then
                    _colStencils.Add(strStencil, strStencil)
                End If

                '
                ' make a csv pair of the stencil and master names
                '
                strFront = p.Field(Of String)("prodMasterFront")
                strFront = "[" & strStencil & "," & strFront & "]"
                If _colMasters.Contains(strFront) = False Then
                    _colMasters.Add(strFront, strFront)
                End If
                strRear = p.Field(Of String)("prodMasterRear")
                strRear = "[" & strStencil & "," & strRear & "]"
                If _colMasters.Contains(strRear) = False Then
                    _colMasters.Add(strRear, strRear)
                End If
                strTop = p.Field(Of String)("prodMasterTop")
                strTop = "[" & strStencil & "," & strTop & "]"
                If _colMasters.Contains(strTop) = False Then
                    _colMasters.Add(strTop, strTop)
                End If
            Next


            preLoadStencils()
            preloadComponents()



        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

        If _colMasters IsNot Nothing Then
            _colMasters = Nothing
        End If
        If _colMasters IsNot Nothing Then
            _colMasters = Nothing
        End If


    End Sub


    Public Sub preLoadDocumentStencilFromCollection(ByVal dictProducts As Dictionary(Of Int16, Int32))


        If _colMasters Is Nothing Then
            _colMasters = New Collection
        Else
            _colMasters.Clear()
        End If

        If _colStencils Is Nothing Then
            _colStencils = New Collection
        Else
            _colStencils.Clear()
        End If


        Try


            Dim intVendorKey As Int32 = -1
            Dim strStencil As String = ""
            Dim strFront As String = ""
            Dim strRear As String = ""
            Dim strTop As String = ""

            Dim productQuery = From product In m_dt.AsEnumerable() _
                    Select product

            For Each p In productQuery
                intVendorKey = p.Field(Of Int32)("prodKey")
                If dictProducts.ContainsValue(intVendorKey) = True Then
                    strStencil = p.Field(Of String)("prodStencil")
                    If _colStencils.Contains(strStencil) = False Then
                        _colStencils.Add(strStencil, strStencil)
                    End If
                    strFront = p.Field(Of String)("prodMasterFront")
                    strFront = "[" & strStencil & "," & strFront & "]"
                    If _colMasters.Contains(strFront) = False Then
                        _colMasters.Add(strFront, strFront)
                    End If
                    strRear = p.Field(Of String)("prodMasterRear")
                    strRear = "[" & strStencil & "," & strRear & "]"
                    If _colMasters.Contains(strRear) = False Then
                        _colMasters.Add(strRear, strRear)
                    End If
                    strTop = p.Field(Of String)("prodMasterTop")
                    strTop = "[" & strStencil & "," & strTop & "]"
                    If _colMasters.Contains(strTop) = False Then
                        _colMasters.Add(strTop, strTop)
                    End If
                End If
            Next



            preLoadStencils()
            preloadComponents()



        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

        If _colStencils IsNot Nothing Then
            _colStencils = Nothing
        End If
        If _colMasters IsNot Nothing Then
            _colMasters = Nothing
        End If


    End Sub



    '
    ' go through the component data and load the master shapes into
    ' the document stencil. The collection passed in is csv strings
    '
    Private Sub preloadComponents()

        Dim strMaster As String
        Dim strStencil As String
        Dim m_clsComp = New DC_Rack.Objects.clsComponents(drawingApplication, drawingDocument)

        Try

            Dim intX As Integer
            Dim vsoDocs As Microsoft.Office.Interop.Visio.Documents = Me.drawingApplication.Documents
            Dim vsoStencil As Microsoft.Office.Interop.Visio.Document
            Dim vsoMasters As Microsoft.Office.Interop.Visio.Masters = Me.drawingDocument.Masters
            Dim vsoMaster As Microsoft.Office.Interop.Visio.Master

            Dim returnValue As String()


            Dim colPair As Collection = New Collection
            For intX = 1 To _colMasters.Count
                Dim strMasterPair As String = _colMasters.Item(intX)

                strMasterPair = strMasterPair.Replace("[", "")
                strMasterPair = strMasterPair.Replace("]", "")
                returnValue = strMasterPair.Split({","c}, _
                        2, StringSplitOptions.None)


                strStencil = returnValue(0)
                strMaster = returnValue(1)

                If strMaster <> "na" _
                    And strMaster <> "" Then
                    ' first check to see if the shape is in the
                    ' document stencil since it can error out, wrap in try-catch
                    Dim lclMaster As Microsoft.Office.Interop.Visio.Master = Nothing
                    Try
                        lclMaster = Me.drawingDocument.Masters(strMaster)
                    Catch
                    End Try
                    If (lclMaster Is Nothing) Then
                        ' load the masters (the stencils were preloaded)
                        vsoStencil = vsoDocs.Item(strStencil)
                        vsoMaster = Nothing
                        ' make sure it is in the stencil
                        Try
                            vsoMaster = vsoStencil.Masters.Item(strMaster)
                        Catch
                        End Try
                        If vsoMaster IsNot Nothing Then
                            ' put the master into the document, not the page
                            lclMaster = Me.drawingDocument.Drop(vsoMaster, 0, 0)

                            ' clear any shape data definitions and then add our
                            ' component definitions
                            Dim mstShape As Microsoft.Office.Interop.Visio.Shape
                            Dim intCt As Integer
                            Dim intY As Integer
                            ' make a copy of the master
                            Dim cpyMaster As Microsoft.Office.Interop.Visio.Master
                            cpyMaster = Nothing
                            cpyMaster = lclMaster.Open
                            mstShape = cpyMaster.Shapes(1)
                            intY = -1
                            intCt = -1
                            If mstShape.SectionExists(VisSectionIndices.visSectionProp, False) = True Then
                                intCt = mstShape.RowCount(VisSectionIndices.visSectionProp)
                                For intY = intCt To 0 Step -1
                                    If mstShape.CellsSRCExists(VisSectionIndices.visSectionProp, intY, VisCellIndices.visCustPropsType, VisExistsFlags.visExistsAnywhere) = True Then
                                        mstShape.DeleteRow(VisSectionIndices.visSectionProp, intY)
                                    End If
                                Next intY
                            End If

                            ' add our component shape data properties
                            m_clsComp.UpdateComponentProperties(mstShape, Nothing)

                            'put it back
                            cpyMaster.Close()
                        Else
                            'Dim errWin As ErrorWindow = New ErrorWindow("product master shape", "unable to find named master" & vbCrLf & strMasterPair)
                            'errWin.ShowDialog()
                            'errWin = Nothing
                        End If
                    End If

                    ' end test for na or blank master name
                End If
HandleNext:
            Next intX

        Catch com As COMException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try


    End Sub

    '
    ' add a collection of stencil documents to the drawing
    ' pass in the active visio application, the stencil path, and a collection of stencil names
    '
    Private Sub preLoadStencils()

        Try

            Dim intX As Integer
            Dim blnLoaded As Boolean = False
            Dim blnFound As Boolean = False
            Dim strStencil As String = ""
            Dim strNew As String


            ' now load the rest of the stuff
            For intX = 1 To _colStencils.Count

                strStencil = _colStencils.Item(intX)
                blnLoaded = m_clsVisio.TestStencilLoaded(Me.drawingApplication, strStencil)

                If blnLoaded = False Then
                    strNew = _StencilPath & strStencil
                    ' with a preload open as hidden
                    blnFound = m_clsVisio.visioOpenStencil(Me.drawingApplication, strNew, _
                                                      VisOpenSaveArgs.visOpenHidden)
                    If blnFound = False Then
                        MsgBox("Failed to load " & strNew)
                    End If
                End If

            Next intX


        Catch com As COMException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub


    '
    ' based on the selected datarow and radiobutton, add a shape to the visio control
    ' and zoom in on it.
    '
    Public Sub dropProductInDrawingAndZoom _
            (ByVal dcProd As dc_Product, _
             ByVal dcView As dc_Product.View)

        Try


            Dim targetPage As Microsoft.Office.Interop.Visio.Page
            targetPage = DirectCast(Me.drawingWindow.PageAsObj, Microsoft.Office.Interop.Visio.Page)

            Dim visShapes As Microsoft.Office.Interop.Visio.Shapes = targetPage.Shapes
            Dim visShape As Microsoft.Office.Interop.Visio.Shape
            If visShapes.Count > 0 Then
                For Each visShape In visShapes
                    visShape.Delete()
                Next
            End If

            Dim strMasterName As String = ""
            Select Case dcView
                Case View.viewFront
                    strMasterName = dcProd.prodMasterFront
                Case View.viewTop
                    strMasterName = dcProd.prodMasterTop
                Case Else
                    strMasterName = dcProd.prodMasterRear
            End Select


            ' first check to see if the shape is in the
            ' document stencil since it can error out, wrap in try-catch
            Dim networkMaster As Microsoft.Office.Interop.Visio.Master = Nothing
            Try
                networkMaster = Me.drawingDocument.Masters(strMasterName)
            Catch
            End Try
            If (networkMaster IsNot Nothing) Then
                Dim strFound As String = ""

                Dim dropLocationX As Double = 0
                Dim dropLocationY As Double = 0

                ' Drop the master at the initial location. The end user
                ' can drag the shape around on the drawing page after it's
                ' dropped.


                Dim pageSheet As Microsoft.Office.Interop.Visio.Shape = targetPage.PageSheet

                ' put it in the width
                If pageSheet.CellExists("pagewidth", False) = True Then
                    dropLocationX = pageSheet.Cells("pagewidth").ResultIU / 2
                End If

                ' put it in the height
                If pageSheet.CellExists("pageheight", False) = True Then
                    dropLocationY = pageSheet.Cells("pageheight").ResultIU / 2
                End If

                visShape = targetPage.Drop(networkMaster, dropLocationX, dropLocationY)

                Dim dblLeft As Double = 0
                Dim dblTop As Double = 0
                Dim dblWidth As Double = 0
                Dim dblHeight As Double = 0
                Dim visCell As Microsoft.Office.Interop.Visio.Cell

                visCell = visShape.Cells("width")
                dblWidth = visCell.ResultIU

                visCell = visShape.Cells("height")
                dblHeight = visCell.ResultIU

                visCell = visShape.Cells("pinx")
                dblLeft = visCell.ResultIU - (dblWidth * 0.5)

                visCell = visShape.Cells("piny")
                dblTop = visCell.ResultIU + dblHeight + (dblHeight * 0.2)

                Me.drawingWindow.SetViewRect(dblLeft, dblTop, dblWidth, dblHeight)
                Me.drawingWindow.DeselectAll()

            Else



            End If


        Catch com As COMException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub





#End Region

#Region " Constructor "

    Public Sub New()
        Try


            m_db = DatabaseFactory.CreateDatabase()

            strUserId = Environment.UserDomainName & "/" & Environment.UserName

            '
            ' init an object class so that the default constants are available
            ' to the table definitions
            '
            If m_dc Is Nothing Then
                m_dc = New dc_Product(strUserId)
            Else
                m_dc = Nothing
                m_dc = New dc_Product(strUserId)
            End If

            initDataSetAndTable()

            _colPortMaster = New Collection(Of dc_PortBase)
            _colSlotMaster = New Collection(Of dc_SlotBase)

            _MasterErrors = New Collection
            _colStencils = New Collection
            _colMasters = New Collection
            _StencilPath = My.Settings.path_custom_stencils



            m_clsVisio = New DC_Rack.Support.clsVisioSupport

            _ProductCount = 0

            m_updateCommand = Nothing
            m_insertCommand = Nothing
            m_deleteCommand = Nothing

            buildInsertProductDataCommand()
            buildDeleteProductDataCommand()
            buildUpdateProductDataCommand()


        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub





    '
    '
    '
    Private Sub NullAndRelease(ByVal runtimeObject As Object)

        Try

            If Not (runtimeObject Is Nothing) Then

                ' The RCW's reference count gets incremented each time the
                ' COM pointer is passed from unmanaged to managed code.
                ' Call ReleaseComObject in a loop until it returns 0 to be
                ' sure that the underlying COM object gets released.
                Dim i As Integer
                Do
                    i = System.Runtime.InteropServices.Marshal. _
                        ReleaseComObject(runtimeObject)
                Loop While i > 0
            End If
        Finally
            runtimeObject = Nothing
        End Try
    End Sub


#End Region


    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub


    '
    ' create a csv string with end brackets from a collection
    '
    Private Function BuildCsvString _
        (ByVal colA As Collection) _
        As String

        Dim intY As Integer
        Dim strCsv As String = "[]"
        Try

            If (colA Is Nothing) _
                Or (colA.Count = 0) Then
                Exit Try
            Else
                With colA
                    ' start bracket
                    strCsv = "["
                    For intY = 1 To colA.Count
                        strCsv = strCsv & CStr(colA.Item(intY))
                        If intY <> colA.Count Then
                            strCsv = strCsv & ","
                        End If ' test for last position
                    Next intY
                    ' end bracket
                    strCsv = strCsv & "]"
                End With
            End If

        Catch ex As Exception
            '********* visio snippet vb.net visXXXX ******************
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
            strCsv = "[]"
        End Try

        BuildCsvString = strCsv

    End Function





End Class
